window.addEventListener("DOMContentLoaded", function() {
	let showReminderImg = document.getElementById("show-reminder-div");
		let protectInfoDiv = document.getElementsByClassName("protect-info")[0];
		let closeReminderImg = document.getElementsByClassName("close-reminder-img")[0];
		protectInfoDiv.addEventListener("click", function() {
			showReminderImg.style.display = "block";
			
		});
		closeReminderImg.addEventListener("click", function() {
			showReminderImg.style.display = "none";
			
		});
	jQuery.noConflict();
	jQuery(function($) {
		//生产轮播图所需要的小圆圈li
		function createPointerLi() {
			let carouselUL = $(".carousel-div1 >ul.display-flex:first");
			let nums = carouselUL.children().length;
			let width = carouselUL.children().get(0).offsetWidth;
			let lis = null;
			let startIndex = 0;
			for(let i = 0; i < nums; i++) {
				lis = $(`<li>${i+1}</li>`);
				$(".order-pointers").append(lis);
			}
			carouselUL.get(0).addEventListener("touchstart", function(e1) {
				e1 = e1 || window.event;
				let moveX1 = e1.touches[0].pageX;
				carouselUL.get(0).addEventListener("touchmove", function(e2) {
					e2 = e2 || window.event;
					let moveX2 = e2.touches[0].pageX;
					let isMove = (carouselUL.get(0).offsetLeft < 0 && carouselUL.get(0).offsetLeft > -((nums - 1) * width)) ?
						true : false;
					let minusMove = moveX2 - moveX1; // 小于0，就是左划动；大于0，就是右划动
					if(startIndex > -1 || startIndex < nums) {
						if(minusMove > 0 && Math.abs(minusMove) > 50 && startIndex > 0) {
							//手指向右划动，offsetLeft增大
							startIndex--;
							circleCarousel(carouselUL, $(".order-pointers").children().eq(startIndex), -(startIndex * width));
							console.log(888);
							return;
						}
						if(minusMove < 0 && Math.abs(minusMove) > 50 && startIndex < 2) {
							startIndex++;
							circleCarousel(carouselUL, $(".order-pointers").children().eq(startIndex), -(startIndex * width));

							console.log(999);
							return;
						}
						return;
					}

				});

			});
			$(".order-pointers").children().click(function() {
				let _this = $(this).index();
				startIndex = _this;
				let moveLeft = _this * width;

				circleCarousel(carouselUL, $(this), -moveLeft);
			});

			function circleCarousel(obj1, obj2, index) {
				obj1.stop(true).animate({
						left: index + "px"
					},
					"slow", "swing"
				);
				obj2.css({
					"background": "purple"
				}).siblings().css({
					"background": "#f16622"
				});
			}
			$(window).resize(function() {
				width = carouselUL.children().get(0).offsetWidth;
				startIndex = 0;
				/*carouselUL.stop(true).animate(
					{
						left: "0px"
					},
					"slow", "swing"
				);
				$(".order-pointers").children().eq(startIndex).css({
					"background": "purple"
				}).siblings().css({
					"background": "#f16622"
				});*/
				circleCarousel(carouselUL, $(".order-pointers").children().eq(startIndex), 0);
			});
		}
		createPointerLi();
		$(".show-info").click(function() {
			$(this).parent().css({
				"height": "9rem"
			});

		});
		$(".special-rules .selection-of-cars").click(function() {
			$(this).stop(true).toggleClass("active").siblings().stop(true).removeClass("active");
		});

		$(".remove-destination").click(function() {
			let nums = $(".remove-destination").parents("#input-destination").children(".other-destinations").length;
			if(nums > 1) {
				$(this).parent().remove();
				return;
			}

		});
		$(".add-destination").click(function() {
			let nums = $(".remove-destination").parents("#input-destination").children(".other-destinations").length;
			if(nums < 5) {
				let $ele = $(".other-destinations").first().clone(true);
				$("#last-destination").before($ele);
				$ele = null;
			}
		});

		$("#extra-input-area div.float-right").click(function() {
			$(this).children("div").stop(true).toggleClass("background-color-orange")
				.find("a").stop(true)
				.toggleClass("position-absolute-right");

		});
		$("#follow-car-person > a").click(function() {
			$(this).stop(true).toggleClass("follow-car-selection")
				.siblings().removeClass("follow-car-selection");
		});
		// 点击切换显示/隐藏点击选中额外需求的ul列表的命令
		$("#extra-input-area .ul-slide-in").click(function() {
			$("#add-extra-conditions").stop(true).slideToggle(300);
		});
		$("#add-extra-conditions .ul-slide-out").click(function() {
			$("#add-extra-conditions").stop(true).slideUp(300);
		});
		/*$("section#section-area").click(function() {
			if(confirm("对不起，您还未登录，暂时需要您先去登录账号再继续使用相关功能。")) {
				location.replace("userLogin.html");
				return;
			}
			alert("您已取消登录，只能浏览下订单的部分页面。");
		});*/
	});
	
});